﻿Imports DevExpress.XtraReports.UI
Public Class FormBarCodePrint
    Dim objMstJL As New clsMstJL
    Dim objProdInfo As New clsProdInfo
    Private Sub FormBarCodePrint_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        txtBarCode.Focus()
        getJlList()
    End Sub

    Private Sub getJlList()
        Dim dtMstJL As DataTable = objMstJL.getProdInfoListByMstType("胶片")
        cmbJPXH_SJ.DisplayMember = "mst_value"
        cmbJPXH_SJ.ValueMember = "mst_value"
        cmbJPXH_SJ.DataSource = dtMstJL
    End Sub

    Private Sub txtBarCode_KeyDown(sender As Object, e As KeyEventArgs) Handles txtBarCode.KeyDown
        If e.KeyCode = Keys.Enter Then
            Search()
        End If
    End Sub

    Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
        Search()
    End Sub

    Private Sub Search()
        If String.IsNullOrEmpty(txtBarCode.Text.Trim()) = False Then
            Dim dtPI As DataTable = objProdInfo.getProdInfoByProdId(txtBarCode.Text.Trim())
            dgv.AutoGenerateColumns = False
            dgv.DataSource = dtPI
        Else
            MsgBox("请扫描或输入标签号", vbYes, "提示")
        End If
    End Sub

    Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
        If dgv.SelectedRows.Count > 0 Then
            Dim report As New XtraReport3()
            Dim printTool As New ReportPrintTool(report)
            report.Xr_lbl_support_model.Text = dgv.SelectedRows(0).Cells("prod_spec_name").Value.ToString()
            report.Xr_lbl_project_name.Text = dgv.SelectedRows(0).Cells("mes_project_name").Value.ToString()
            report.Xr_lbl_project_code.Text = dgv.SelectedRows(0).Cells("project_no").Value.ToString() '项目编号
            report.Xr_lbl_yzz_DateTime.Text = dgv.SelectedRows(0).Cells("org_time").Value.ToString() '预组装时间
            report.XrBarCode1.Text = dgv.SelectedRows(0).Cells("prod_id").Value.ToString() '标签号
            report.Xr_lbl_jp_type.Text = dgv.SelectedRows(0).Cells("jp_type").Value.ToString() '胶料类型     
            report.Xr_lbl_gyh.Text = dgv.SelectedRows(0).Cells("steel_seal_no").Value.ToString() '生产编号
            report.Xr_lbl_location.Text = dgv.SelectedRows(0).Cells("location").Value.ToString() '库位编号
            printTool.Print()
        End If
    End Sub

    Private Sub btnSaveJlType_Click(sender As Object, e As EventArgs) Handles btnSaveJlType.Click
        If dgv.SelectedRows.Count > 0 Then
            If MsgBox("确认要修改胶料吗？", vbYesNo, "提示") = vbYes Then
                Dim prodId As String = dgv.SelectedRows(0).Cells("prod_id").Value.ToString()
                Dim rtn As Integer = objProdInfo.updateProdInfoJpType(prodId, cmbJPXH_SJ.Text.Trim())
                If rtn <> -2 Then
                    MsgBox("修改胶料成功", vbYes, "提示")
                Else
                    MsgBox("修改胶料失败", vbYes, "提示")
                End If
                Search()
            End If
        Else
            MsgBox("请先查询支座信息", vbYes, "提示")
        End If
    End Sub
End Class